package com.bby.screentool.views;

import android.content.Context;
import android.content.res.ColorStateList;
import android.util.AttributeSet;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatButton;

import com.bby.screentool.R;
import com.bby.screentool.base.RecordStatus;

public class RecordButton extends AppCompatButton {
    public RecordButton(@NonNull Context context) {
        super(context);
    }

    public RecordButton(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public RecordButton(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setStatus(RecordStatus status) {
//        setEnabled(status!=RecordStatus.UNAVAILABLE);
        switch (status) {
            case UNAVAILABLE:
                setText(getResources().getString(R.string.loading));
                setBackgroundTintList(ColorStateList.valueOf(getColor(R.color.unavailable)));
                break;
            case RUNNING:
                setText(getResources().getString(R.string.stop_record));
                setBackgroundTintList(ColorStateList.valueOf(getColor(R.color.stop)));
                break;
            case STOP:
                setText(getResources().getString(R.string.start_record));
                setBackgroundTintList(ColorStateList.valueOf(getColor(R.color.ready)));
                break;
            case READY:
                setBackgroundTintList(ColorStateList.valueOf(getColor(R.color.ready)));
                break;
        }
    }

    private int getColor(int id) {
        return getResources().getColor(id, getContext().getTheme());
    }



}